<?php
/**
 * Created by PhpStorm.
 * User: N
 * Date: 2017/12/13
 * Time: 15:17
 */
namespace common\models;

use Yii;
use yii\base\Model;
use common\models\Models;
use backend\modules\content\models\Sitemodel;
use backend\modules\content\models\Modelfield;
use yii\db\ActiveRecord;
use yii\data\ActiveDataProvider;
use yii\data\Pagination;
use backend\modules\admin\models\Admin;
use common\models\User;


/**
 * This is the model class for table "order_log".
 *
 * @property string $catid
 * @property string $siteid
 **/
class OrderLog extends ActiveRecord
{
     /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return '{{%order_log}}';
    }

    /**
    * 验证规则
    */
    public function rules()
    {
        return [
            [['deallog','order_id'],'required','message'=>'不能为空'],
            [['deallog','reply','dealcontent'],'string','message'=>'格式不正确'],
            [['log_id','order_id','uid','isadmin','status','created_at','updated_at','opstatus'],'number','message'=>'格式不正确'],
        ];
    }

    public function beforeSave($insert){
        if($insert){
            $this->status=0;
            //插入时补充操作
            $this->created_at = time();
            $this->updated_at = time();
        }else{
            //修改时补充操作
            $this->updated_at = time();
        }
      
        return true;

    }



        /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'order_id' => '工单名称',
            'uid' => '操作者',
            'deallog' => '操作详情',
            'reply' => '回复',
            'status'  => '日志状态',
            'dealcontent' => '工单处理过程记录'
        ];
    }

    public function getFromname()
    {
        if($this->isadmin == 1){
            $adminmodel = Admin::find()->where(['userid' => $this->uid])->one();
            return $adminmodel->username;
        }elseif($this->isadmin == 0){
            $usermodel = User::find()->where(['id' => $this->uid])->one();
            return $usermodel->realname;
        }
    }

    public function getOpclass()
    {
        switch ($this->opstatus){
            case '1':
                return 'sl-danger';
                break;
            case '2':
                return 'sl-success';
                break;
            case '3':
                return 'sl-primary';
                break;
            case '4':
                return 'sl-warning';
                break;
            case '5':
                return '';
                break;
            case '6':
                return 'sl-danger';
                break;
            case '7':
                return 'sl-success';
                break;
            case '8':
                return 'sl-primary';
                break;
            case '9':
                return 'sl-warning';
                break;
            case '10':
                return '';
                break;
            default:
                return 'sl-success';
        }
    }




    


}